﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Resources/master/MatrixBase.Master" AutoEventWireup="true" CodeBehind="UserManage.aspx.cs" Inherits="WebAppMatrix.Website.Pages.SystemBase.MatrixUser.UserManage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            $('#grid').datagrid({
                height: 340,
                url: '/API/SystemBase/User/getList/',
                idField: 'UserID',
                fitColumns: true,
                rownumbers: true,
                pagination: true,
                singleSelect: true,
                columns: [[
                    { field: 'LoginName', title: '姓名', width: 120, align: 'left' },
                    { field: 'Status', title: '状态', width: 80, align: 'left' }
                ]],
                onLoadSuccess: function (data) {

                },
                onBeforeLoad: function (param) {
                    var keyword = $('#txtKeyword').searchbox('getValue');
                    param.keyword = keyword;
                }
            });
        });

        function doSearch() {
            $("#grid").datagrid('reload');
        }

        function doAdd() {
            $('#winAddEdit').window({
                modal: true,
                maximizable: false,
                minimizable: false,
                collapsible: false,
                title: '新增用户',
                width: 400,
                height: 230
            });
            resetWinAdd();
        }

        function resetWinAdd() {
            $('#txtLoginName, #txtPassword').val('');
            $('#cmbStatus').combobox('setValue', '64');
        }

        function add_save() {
            if ($('#txtLoginName, #txtPassword').validatebox('validate')) {
                var param = {
                    LoginName: $('#txtLoginName').val(),
                    Password: $('#txtPassword').val(),
                    Status: $('#cmbStatus').combobox('getValue')
                }
                $.ajax({
                    url: '/API/SystemBase/User/add/',
                    data: param,
                    success: function () {
                        //$('#winAddEdit').window('close');
                        resetWinAdd();
                        doSearch();
                    }
                });
            }
        }

        function doDelete() {
            var selected = $('#grid').datagrid('getSelected');
            if (selected) {
                $.ajax({
                    url: '/API/SystemBase/User/delete/' + selected.UserID,
                    success: function () {
                        doSearch();
                    }
                });
            }
            else {
                $.messager.alert('提示', '请选择要删除的用户');
            }
        }

        function doEdit() {
            //$("#grid").datagrid('loadData', { total: 0, rows: [] });
        }

        function edit_save() {

        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="server">
    <div id="toolbar" class="matrix-toolbar">
        <a id="btnAdd" iconcls="icon-add" onclick="doAdd();" class="easyui-linkbutton" plain="true">新增</a>
        <a id="btnEdit" iconcls="icon-edit" class="easyui-linkbutton" plain="true" onclick="doEdit();">编辑</a>
        <a id="btnDelete" iconcls="icon-remove" class="easyui-linkbutton" plain="true" onclick="doDelete();">删除</a>
        <input type="text" value="" id="txtKeyword" style="width: 150px;" class="easyui-searchbox"
            prompt="输入关键字查询" searcher="doSearch" />
    </div>
    <div id="grid">
    </div>
    <div style="display: none;">
        <div id="winAddEdit">
            <div class="matrix-toolbar">
                <a iconcls="icon-save" class="easyui-linkbutton" plain="true" onclick="add_save();">保存</a>
            </div>
            <div class="matrix-content">
                <div class="matrix-row">
                    <label for="txtLoginName">登陆名：</label>
                    <input type="text" id="txtLoginName" class="easyui-validatebox" required="true" maxlength="50" />
                </div>
                <div class="matrix-row">
                    <label for="txtPassword">密码：</label>
                    <input type="password" id="txtPassword" class="easyui-validatebox" required="true" maxlength="16" />
                </div>
                <div class="matrix-row">
                    <label for="cmbStatus">状态：</label>
                    <select id="cmbStatus" class="easyui-combobox" style="width: 60px;">
                        <option value="64">启用</option>
                        <option value="128">停用</option>
                    </selec>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
